package com.woniu.zsd.permission.mapper;

import com.woniu.dto.AdminInfoDto;
import com.woniu.form.SelAdminInfoForm;
import com.woniu.form.UpdateAdminInfoForm;
import com.woniu.zsd.permission.entity.AdminInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-03-27
 */
public interface AdminInfoMapper extends BaseMapper<AdminInfo> {

     int updateRoleByAdminId(@Param("adminId") Integer adminId,@Param("role") Integer role);

    List<AdminInfo> selAdminInfoById(SelAdminInfoForm saif);

    @Select("SELECT site_id FROM admin_info WHERE admin_id = #{adminId}")
    Integer selectSiteIdByAdminId(@Param("adminId") Integer adminId);

    @Select("SELECT * FROM admin_info WHERE site_id = #{siteId} AND role = 3")
    List<AdminInfo> selectAdminsBySiteIdAndRole(@Param("siteId") Integer siteId);


    int deleteAdminInfoById(Integer adminId);

    AdminInfo selectAdminInfoById(Integer adminId);

    @Select("SELECT COUNT(*) FROM zsd_permission.admin_info WHERE phone = #{phone} AND is_delete = '1'")
    int checkPhoneExists(@Param("phone") String phone);

    @Select("SELECT COUNT(*) FROM zsd_permission.admin_info WHERE username = #{username} AND is_delete = '1'")
    int checkUsernameExists(@Param("username") String username);
    // 添加批量查询方法
    List<AdminInfo> selectAdminInfoByIds(@Param("adminIds")Set<Integer> adminIds);

    @Select("select * from admin_info where admin_id = #{adminId}")
    AdminInfoDto selectAdminInfo(Integer adminId);

    int insertAdminInfo(@Param("name") String name,
                        @Param("phone") String phone,
                        @Param("role") Integer role,
                        @Param("siteId") Integer siteId,
                        @Param("username") String username,
                        @Param("expireTime") String expireTime);

    void updateAdminInfo(@Param("adminId") Integer adminId,
                         @Param("name") String name,
                         @Param("phone") String phone,
                         @Param("role") Integer role,
                         @Param("state") String state,
                         @Param("siteId") Integer siteId,
                         @Param("username") String username,
                         @Param("expireTime") String expireTime);

    @Update("UPDATE zsd_permission.admin_info SET password = #{newPassword} WHERE admin_id = #{adminId}")
    int updatePassword(@Param("adminId") Integer adminId, @Param("newPassword") String newPassword);

}